package cn.pink.common.support.tools.global;

import cn.pink.common.support.tools.cache.CacheTool;
import cn.pink.core.Session;
import cn.pink.core.config.CacheConfig;

/**
 * 全局工具
 * @Author: pink
 * @Date: 2022/7/5 15:24
 */
public class GlobalTool {
    private static GlobalTool tool = new GlobalTool();

    private GlobalTool() {

    }

    public static GlobalTool getInstance() {
        return tool;
    }

    /**
     * 判断角色是否在线
     */
    public boolean isOnline(String humanId) {
        return CacheTool.getInstance().getCache(CacheConfig.SESSION).get(humanId) != null;
    }

    /**
     * 获取在线角色session
     */
    public Session getSession(String humanId) {
        return (Session) CacheTool.getInstance().getCache(CacheConfig.SESSION).get(humanId);
    }

    /**
     * 修改在线角色session
     */
    public void updateSession(String humanId, Session session) {
        CacheTool.getInstance().getCache(CacheConfig.SESSION).put(humanId, session);
    }
}
